# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  before_filter :configure_charsets
  
  def configure_charsets
    @response.headers["Content-Type"]="text/html; charset=utf-8"
    suppress(ActiveRecord::StatementInvalid) do
      ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
    end
  end
  
  def verify_session
    if(!session[:user])
      flash[:notice] = "请先登录!"
      #        将请求中的parameter保存在flash,当用户成功登录后, 直接跳转到他原先想去的页面
      flash[:request] = request.parameters
      redirect_to :controller => 'login' , :action => 'login'
    end
  end
  
  def gettag_counts
    @tag_counts= Book.tag_counts
  end
    
end